package com.cn.sl.server.common.enumerate

import com.cn.sl.server.common.dto.EnumData
import com.fasterxml.jackson.annotation.JsonCreator

enum class ExpandFieldType(val alias: String) {
    Text("文本"),
    ApprovalUserSelect("审批人"),
    UserSelect("用户");

    fun toEnumData(): EnumData<Any> {
        return EnumData(
            label = this.alias,
            value = this.name
        )
    }

    companion object {
        @JsonCreator
        fun create(code: String): ExpandFieldType? {
            for (item in ExpandFieldType.entries) {
                if (item.toString() == code) {
                    return item
                }
            }
            return null
        }

        fun toEnumDataList(): List<EnumData<Any>> {
            return ExpandFieldType.entries.map {
                EnumData(
                    label = it.alias,
                    value = it.name
                )
            }
        }
    }
}